package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.LineStyleInfo;
import com.fr.chart.core.FoldLine;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.MarkerGlyph;
import java.awt.Graphics;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;

public class LinePlotGlyph extends CategoryPlotGlyph
{
  private static final long serialVersionUID = -1824689734124193168L;
  public static final String XML_TAG = "LinePlotGlyph";
  private boolean isShowLine = true;
  private boolean isShowMarker = true;

  public void layoutDataSeriesGlyph()
  {
    for (int i = 0; i < getSeriesSize(); ++i)
    {
      DataSeries localDataSeries = getSeries(i);
      int j = 0;
      for (int k = 0; k < localDataSeries.getDataPointCount(); ++k)
        if (!(localDataSeries.getDataPoint(k).isValueIsNull()))
          ++j;
      double[] arrayOfDouble1 = new double[j];
      double[] arrayOfDouble2 = new double[j];
      j = 0;
      GeneralPath localGeneralPath = new GeneralPath(1);
      int l = 1;
      for (int i1 = 0; i1 < localDataSeries.getDataPointCount(); ++i1)
      {
        DataPoint localDataPoint = localDataSeries.getDataPoint(i1);
        if (localDataPoint.isValueIsNull())
        {
          if (isNullValueBreak())
            l = 1;
        }
        else
        {
          float f2;
          double d1 = getDataPointPercentValue(i, i1);
          float f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(i1, 0.5D).getX();
          if (isStacked())
          {
            double d2 = 0.0D;
            for (int i2 = i - 1; i2 >= 0; --i2)
              d2 += getDataPointPercentValue(i2, i1);
            f2 = (float)getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d2 + d1).getY();
          }
          else
          {
            f2 = (float)getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d1).getY();
          }
          arrayOfDouble1[j] = f1;
          arrayOfDouble2[j] = f2;
          ++j;
          if (l != 0)
          {
            localGeneralPath.moveTo(f1, f2);
            l = 0;
          }
          else
          {
            localGeneralPath.lineTo(f1, f2);
          }
          if (isShowMarker())
          {
            MarkerGlyph localMarkerGlyph = new MarkerGlyph();
            localMarkerGlyph.dealCondition4Line(getSeriesCollection(), i);
            localMarkerGlyph.setShape(new Rectangle2D.Double(f1 - 5.0F, f2 - 5.0F, 10.0D, 10.0D));
            localDataPoint.setDrawImpl(localMarkerGlyph);
          }
          else
          {
            localDataPoint.setShape(new Rectangle2D.Double(f1 - 5.0F, f2 - 5.0F, 10.0D, 10.0D));
          }
          dealDataPointLabelBounds(localDataPoint, i);
        }
      }
      if (isShowLine())
      {
        FoldLine localFoldLine = new FoldLine(localGeneralPath);
        localDataSeries.setDrawImpl(localFoldLine);
        localFoldLine.getLineStyleInfo().dealCondition(getSeriesCollection(), i);
      }
      if (!(isStacked()))
        trendLineFitting(arrayOfDouble1, arrayOfDouble2, i);
    }
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    super.draw(paramGraphics);
  }

  public void setShowLine(boolean paramBoolean)
  {
    this.isShowLine = paramBoolean;
  }

  public boolean isShowLine()
  {
    return this.isShowLine;
  }

  public void setShowMarker(boolean paramBoolean)
  {
    this.isShowMarker = paramBoolean;
  }

  public boolean isShowMarker()
  {
    return this.isShowMarker;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("LinePlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("ShowLine", this.isShowLine).attr("ShowMarker", this.isShowMarker).end();
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("ShowLine")) != null)
          this.isShowLine = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("ShowMarker")) != null)
          this.isShowMarker = Boolean.valueOf(str2).booleanValue();
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof LinePlotGlyph))
      return false;
    LinePlotGlyph localLinePlotGlyph = (LinePlotGlyph)paramObject;
    if (!(super.equals(localLinePlotGlyph)))
      return false;
    if (localLinePlotGlyph.isShowLine != this.isShowLine)
      return false;
    return (localLinePlotGlyph.isShowMarker == this.isShowMarker);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    LinePlotGlyph localLinePlotGlyph = (LinePlotGlyph)super.clone();
    return localLinePlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("isShowLine", this.isShowLine);
    localJSONObject.put("isShowMarker", this.isShowMarker);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "LinePlotGlyph";
  }
}